package cn.edu.cimv.controller;

import cn.edu.cimv.dao.entity.FontMenuSet;
import cn.edu.cimv.dao.entity.Member;
import cn.edu.cimv.dao.entity.MemberItem;
import cn.edu.cimv.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * Created by 门铎 on 2016/8/3.
 */
@Controller
public class CimvController {
    @Autowired private CimvService cimvService;
    @Autowired private NewsService newsService;
    @Autowired private NoticesService noticesService;
    @Autowired private ProjectService projectService;
    @Autowired private RecruitService recruitService;
    @Autowired private LatestService latestService;
    @Autowired private UserService userService;
    @Autowired private OptionService optionService;
    /**
     * 首页
     * @param model
     * @return
     */
    @RequestMapping("/index")
    public String index(Model model){
        //添加最新动态模块
        model.addAttribute("latestList",cimvService.DisplayLatestModule());
        //向前台添加学术动态模块
        model.addAttribute("newsList",cimvService.DisplayNewsModule());
        //向前台添加通知公告模块
        model.addAttribute("noticeList",cimvService.DisplayNoticesModule());
        //向前台添加人才招聘模块
        model.addAttribute("recruitList",cimvService.DisplayRecruitModule());
        //向前台添加科研成果模块
        model.addAttribute("projectList",cimvService.DisplayProjectModule());
        //前台添加友情链接模块
        model.addAttribute("flinkList",cimvService.DisplayFlinkModule());
        return "temple/index";
    }

    /**
     * 联系我们
     * @return
     */
    @RequestMapping("/contact")
    public String contact(Model model){
        model.addAttribute("cata",cimvService.DisplayCata("contact"));
        FontMenuSet fontMenuSet = cimvService.getRelMenu("contact");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/one";
    }

    /**
     *研究生培养
     * @return
     */
    @RequestMapping("/train/{num}")
    public String train(Model model,@PathVariable("num")int num){
        String train;
        if(num!=0){
            train = "train" + num;
        }else{
            train ="train";
        }

        model.addAttribute("cata",cimvService.DisplayCata(train));
        FontMenuSet fontMenuSet = cimvService.getRelMenu(train);
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/one";
    }

    @RequestMapping("student/{flag}")
    public String student(@PathVariable("flag")int flag,Model model){
        if(flag ==0){
            model.addAttribute("title","在读研究生");
        }else{
            model.addAttribute("title","毕业研究生");
        }
        model.addAttribute("studentOuterList",cimvService.DisplayStudents(flag));
        FontMenuSet fontMenuSet = cimvService.getRelMenu("train");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/student-list";
    }

    /**
     *中心介绍
     * @return
     */
    @RequestMapping("/introduce")
    public String introduce(Model model){
        model.addAttribute("cata",cimvService.DisplayCata("introduce"));
        FontMenuSet fontMenuSet = cimvService.getRelMenu("introduce");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/one";
    }
    /**
     *研究方向
     * @return
     */
    @RequestMapping("/direction")
    public String direction(Model model){
       /* model.addAttribute("cata",cimvService.DisplayCata("direction"));*/
        FontMenuSet fontMenuSet = cimvService.getRelMenu("direction");
        model.addAttribute("fontMenuSet",fontMenuSet);
        model.addAttribute("option",optionService.queryTitles("direction"));
        model.addAttribute("optionUnionDirection",cimvService.getOptionUnionDirection("direction"));
        return "temple/direction";
    }

    @RequestMapping("/paper")
    public String paper(Model model){
        model.addAttribute("paperOuterList",cimvService.DisplayPaper());
        FontMenuSet fontMenuSet = cimvService.getRelMenu("paper");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/paper";
    }
    @RequestMapping("latest/{id}")
    public String singleLatest(@PathVariable("id")int id,
                             Model model){
        model.addAttribute("obj",latestService.queryLatestById(id));
        FontMenuSet fontMenuSet = cimvService.getRelMenu("latest");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/single";
    }
    @RequestMapping("news/{id}")
    public String singleNews(@PathVariable("id")int id,
                             Model model){
        model.addAttribute("obj",newsService.queryNewsById(id));
        FontMenuSet fontMenuSet = cimvService.getRelMenu("news");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/single";
    }
    @RequestMapping("notice/{id}")
    public String singleNotices(@PathVariable("id")int id,
                             Model model){
        model.addAttribute("obj",noticesService.queryNoticesById(id));
        FontMenuSet fontMenuSet = cimvService.getRelMenu("notice");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/single";
    }
    @RequestMapping("project/{id}")
    public String singleProject(@PathVariable("id")int id,
                                Model model){
        model.addAttribute("obj",projectService.queryProjectById(id));
        FontMenuSet fontMenuSet = cimvService.getRelMenu("project");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/single";
    }
    @RequestMapping("recruit/{id}")
    public String singleRecruit(@PathVariable("id")int id,
                                Model model){
        model.addAttribute("obj",recruitService.queryRecruitById(id));
        FontMenuSet fontMenuSet = cimvService.getRelMenu("recruit");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/single";
    }
    @RequestMapping("latestList/{pageNum}")
    public String latestList(@PathVariable("pageNum")int pageNum,Model model){
        model.addAttribute("page",cimvService.DisplayLatestList(pageNum));
        model.addAttribute("what","latest");
        FontMenuSet fontMenuSet = cimvService.getRelMenu("latest");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/list";
    }

    @RequestMapping("newsList/{pageNum}")
    public String newsList(@PathVariable("pageNum")int pageNum,Model model){
        model.addAttribute("page",cimvService.DisplayNewsList(pageNum));
        model.addAttribute("what","news");
        FontMenuSet fontMenuSet = cimvService.getRelMenu("news");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/list";
    }
    @RequestMapping("noticeList/{pageNum}")
    public String noticeList(@PathVariable("pageNum")int pageNum,Model model){
        model.addAttribute("page",cimvService.DisplayNoticesList(pageNum));
        model.addAttribute("what","news");
        FontMenuSet fontMenuSet = cimvService.getRelMenu("notice");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/list";
    }
    @RequestMapping("projectList/{pageNum}/{projectType}")
    public String projectList(@PathVariable("pageNum")int pageNum,@PathVariable("projectType")String projectType,Model model){
        model.addAttribute("page",cimvService.DisplayProjectList(pageNum,projectType));
        model.addAttribute("what","project");
        FontMenuSet fontMenuSet = cimvService.getRelMenu("project");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/project-table";
    }
    @RequestMapping("recruitList/{pageNum}")
    public String recruitList(@PathVariable("pageNum")int pageNum,Model model){
        model.addAttribute("page",cimvService.DisplayRecruitList(pageNum));
        model.addAttribute("what","recruit");
        FontMenuSet fontMenuSet = cimvService.getRelMenu("recruit");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/list";
    }
    @RequestMapping("awardsList/{pageNum}")
    public String awardsList(@PathVariable("pageNum")int pageNum,Model model){
        model.addAttribute("page",cimvService.DisplayAwardsTable(pageNum));
        FontMenuSet fontMenuSet = cimvService.getRelMenu("awards");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/awards-table";
    }

    @RequestMapping("honorList/{pageNum}")
    public String honorList(@PathVariable("pageNum")int pageNum,Model model){
        model.addAttribute("page",cimvService.DisplayHonorTable(pageNum));
        FontMenuSet fontMenuSet = cimvService.getRelMenu("honor");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/honor-table";
    }
    @RequestMapping("paperList/{pageNum}/{paperType}")
    public String paperList(@PathVariable("pageNum")int pageNum,@PathVariable("paperType")String paperType,Model model){
        model.addAttribute("page",cimvService.DisplayPaperTable(pageNum,paperType));
        FontMenuSet fontMenuSet = cimvService.getRelMenu("paper");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/paper-table";
    }
    @RequestMapping("patentList/{pageNum}")
    public String patentList(@PathVariable("pageNum")int pageNum,Model model){
        model.addAttribute("page",cimvService.DisplayPatentTable(pageNum));
        FontMenuSet fontMenuSet = cimvService.getRelMenu("patent");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/patent-table";
    }
    @RequestMapping("memberList/{pageNum}")
    public String memberList(@PathVariable("pageNum")int pageNum,Model model){
        model.addAttribute("page",cimvService.DisplayMemberList(pageNum));
        FontMenuSet fontMenuSet = cimvService.getRelMenu("member");
        model.addAttribute("fontMenuSet",fontMenuSet);
        return "temple/member-list";
    }

    @RequestMapping("member/{userName}")
    public String member(@PathVariable("userName")String userName,Model model){
        int id = userService.selectMemberId(userName);
        Member member = userService.selectMember(id);
        model.addAttribute("member",member);
        FontMenuSet fontMenuSet = cimvService.getRelMenu("member");
        model.addAttribute("fontMenuSet",fontMenuSet);

        List<MemberItem> memberItemList = userService.selectMemberItems(String.valueOf(id));
        model.addAttribute("memberItems",memberItemList);
        return "temple/member";
    }
}
